#ifndef MINIBASIC_ERRORS_H
#define MINIBASIC_ERRORS_H

#pragma once

#include "stdafx.h"

namespace MiniBasic
{
    class Environment;

    namespace Errors
    {
        enum ERROR_CONDITION
        {
            SYNTAX_ERROR,
            NUMERIC_OVERFLOW,
            SUBSCRIPT_OUT_OF_RANGE,
            OUT_OF_MEMORY, // shouldn't ever happen
            EXPECTED_A_TO,
            DIV_BY_0,
            EQUAL_EXPECTED,
            NOT_A_LINE,
            TOO_MANY_SUBS,
            MISMATCHED_RETURN,
            ALREADY_LOOPING,
            INVALID_NEXT,
            NOT_FOR_VARIABLE,
            EXPECTED_COMMA,
            INVALID_PARAMETER,
            EXPECTED_VARIABLE,
            EXPECTED_INTEGER,
            INTERNAL_FUNCTION_FAILURE,
            USR_DLL_DOESNT_EXIST,
            USR_FUNCTION_DOESNT_EXIST,
            ERRORS_END
        };

        struct ErrorSink
        {
        private:
            std::ostringstream stream;
            const Environment* env;

        public:
            ErrorSink(const Environment* env);

            template<class T>
            ErrorSink& operator<<(const T& t)
            {
                stream << t;
                return *this;
            }

            ~ErrorSink();
        };

        ErrorSink& operator<<(ErrorSink&, ERROR_CONDITION);
        std::string Win32ErrorString(mbint error);
    }
}

#endif
